﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpLearn_Chapter4.Object
{
    class Animal
    {
        public void Run()
        {

        }
        public void Eat() { 
        
        }

        //虚方法
        public virtual void Say() {
            Console.WriteLine("Animal Say");
        }
    }

    class Dog : Animal {
        public override void Say()
        {
            ///base.Say();
            Console.WriteLine("Dog Say");
        }
    }
    class Cat : Animal
    {
        public override void Say()
        {
            base.Say();
            Console.WriteLine("Cat Say");
        }
    }

    internal class ObjectLearn
    {
        Cat cat = new Cat();
        Dog dog = new Dog();
        void Test()
        {
            cat.Run();
            cat.Eat();

            dog.Eat();

            Animal a = new Cat();
            Animal b = new Dog();

            a.Say();
            b.Say();
        }
    }


    //1. 定义类
    public class Person
    {
        public string? Name { get; set; }
        public int Age {  get; set; }

        public void SayHello()
        {
            Console.WriteLine("Hello");
        }
        public Person() { }

        public Person(string ? name, int age)
        {
            Name = name;
            Age = age;
        }   
    }

    public class Test
    {
        //2. 创建对象，初始化对象
        Person p1 = new Person();

        Person p2 = new Person("Mark", 21);

        Person p3 = new Person()
        {
            Name = "Bob",
            Age = 21
        };

        Person p4;  //未初始化

        void TestPerson()
        {
            p1.Name = "Alice";
            p1.Age = 20;
            //3. 使用对象
            p2.SayHello();

        }
    }


    class Line
    {
        private double length;
        public Line()
        {
            Console.WriteLine("This is a line");
        }

        public Line(double length)
        {
            this.length = length;
        }

        public void setLength(double length)
        {
            this.length = length;
        }
    }

    class TestLine
    {
        Line line = new Line();
        void Test()
        {
            line.setLength(10.0);
            Console.ReadKey();
        }
    }


    class GlobalShared
    {
        public static string SchoolName = "山西传媒学院";
        public static string ZipCode = "030619";
    }

    class TestShared
    {
        void GetInfo()
        {
            string schoolName = GlobalShared.SchoolName;
        }
    }
}
